import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

public class MainPanel extends JLayeredPane {
	
	/* Pages */
	public static Background bg = new Background();
	
	public static Login pLogin = new Login();
	public static Dashboard pDashboard = new Dashboard();
	
	public static Employee pEmployee = new Employee();
	
	public static Section pSection = new Section();
	public static ClassList pClassList = new ClassList();
	
	public static GradeComponents pGradeComp = new GradeComponents();
	public static ConductComponents pConductComp = new ConductComponents();
	public static CoCurricularComponents pCoComp = new CoCurricularComponents();
	public static RHGPComponents pRHGPComp = new RHGPComponents();
	
	public static SubjectGrades pSubjGrades = new SubjectGrades();
	public static ConductGrades pCondGrades = new ConductGrades();
	public static CoCurricularGrades pCoCuGrades = new CoCurricularGrades();
	public static RHGPGrades pRHGPGrades = new RHGPGrades();
	public static Attendance pAttendance = new Attendance();

	/* END Pages */
	
	private static Object[] page = new Object[19];{
		page[0] = pLogin;
		page[1] = pDashboard;
		page[2] = pEmployee;
		page[3] = pSection;
		page[4] = pClassList;
		page[5] = pGradeComp;
		page[6] = pSubjGrades;
		page[7] = pConductComp;
		page[8] = pCondGrades;
		page[9] = pCoComp;
		page[10] = pRHGPComp;
		page[11] = pCoCuGrades;
		page[12] = pRHGPGrades;
		page[13] = pAttendance;
		// page[14] = pUMEdit;
		// page[15] = pRfuF;
		// page[16] = pRtfTA;
		// page[17] = pRtfCM;
		// page[18] = pRait;
	}
	
	private static int UserType = 1; //-1-nil 0-system admin; 1-apaa 2-faculty 3-coordinator
	
	public MainPanel() {
		setOpaque(false);
		setSize(700,600);
		setPreferredSize(new Dimension(700,600));

		add(paginator, new Integer(2));

		add(bg, new Integer(0));

		for(int i=0; i<19; i++){
			try {
				add(((JPanel) page[i]), new Integer(1));
			} catch (NullPointerException e) {}
		}
		init();
	}
	
	//User Type Getter and Setter
	public static void setUserType(int u){
		UserType = u;
	}
	
	public static int getUserType() {
		//db commands here
		return UserType;
	}
	
	public static void goToPage(int pageno){
		fullGUIrefresh();
		for(int i=0; i<19; i++){
			try {
				((JPanel) page[i]).setVisible(false);
			} catch (NullPointerException e) {}
		}
		try {
			((JPanel) page[pageno]).setVisible(true);
		} catch (NullPointerException e) {}

		if(pageno == 0)
			bg.changeCurrentImage(0);
		else if(pageno == 1){
			if(getUserType() == 0 || getUserType() == 1)
				bg.changeCurrentImage(1);
		} 
		else if(pageno > 1)
			bg.changeCurrentImage(2);
	}

	// refresh all pages
	public static void fullGUIrefresh(){
		pLogin.refreshGUI();
		pDashboard.refreshGUI();
		pEmployee.refreshGUI();
		/*pTAView.refreshGUI();
		pCMView.refreshGUI();*/
	}
	
	// for gui page testing
	public void init(){
		int x = 0;
		goToPage(x);
		paginator.setSelectedIndex(x);
		//paginator.setVisible(false);
	}
	
	// gui page selector - start
	private String pagenames[] = {"Login", "Select Module",
								  "Employee", "Section", "Class List", "FR - Edit",
								  "TA - View", "TA - Add", "TA - Edit",
								  "CM - View", "CM - Add", "CM - Edit", "test"};
	
	private JComboBox paginator = new JComboBox(pagenames);{
		paginator.setBounds(570,5,120,24);
		paginator.setVisible(false);
		paginator.setSelectedIndex(-1);
		paginator.addActionListener(new ActionListener(){
	
			public void actionPerformed(ActionEvent a) {
				goToPage(paginator.getSelectedIndex());
			}
		});
	}
	// gui page selector - end
}